﻿using System;
using System.Windows;
using System.Windows.Input;
using Caffeine.Examples.Contacts.ViewModel;
using Caffeine.Wpf;

namespace Caffeine.Examples.Contacts.View
{
    public sealed class ContactListWrapper : TransparentElement
    {
        public ContactListWrapper()
        {
            MouseLeftButtonDown += OnLeftMouseButtonDown;
        }

        private void OnLeftMouseButtonDown(Object sender, MouseButtonEventArgs e)
        {
            ContactManagerViewModel contactManager = (sender as FrameworkElement).DataContext as ContactManagerViewModel;
            ContactViewModel contact = (e.OriginalSource as FrameworkElement).DataContext as ContactViewModel;

            if (contact != null && contactManager != null)
            {
                contactManager.SelectContact(contact);
            }
        }
    }
}
